package JUC.assist;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @author mubei
 * @date 2021/11/21
 * @description
 */
public class TestCyclicBarrier {

    public static void main(String[] args) {

        CyclicBarrier barrier = new CyclicBarrier(7, () -> {
            System.out.println("召唤神龙");
        });
        for (int i = 1; i <= 7 ; i++) {
            final int temp = i;
           new Thread(()->{
               System.out.println("拿到第:"+temp);
               try {
                   barrier.await();
               } catch (Exception e) {
                   e.printStackTrace();
               }
           }).start();
        }
    }
}
